//
//  YHBannerWebViewController.m
//  TestYoho
//
//  Created by YiDarren on 17/1/22.
//  Copyright © 2017年 YiDarren. All rights reserved.
//

#import "YHBannerWebViewController.h"
#import "MBProgressHUD+JDragon.h"
#import "MBProgressHUD.h"

@interface YHBannerWebViewController ()<UIWebViewDelegate,UIAlertViewDelegate>



@end

@implementation YHBannerWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"活动详情";
    _webView.delegate = self;
    _urlStr = @"http://www.ssrj.com/mobile/inform/content/201701/330/1_app.html";
    [self addBackButton];
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    NSURL *url = [NSURL URLWithString:_urlStr];
    [_webView loadRequest:[NSURLRequest requestWithURL:url]];
    
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
}

#pragma mark -webView代理方法
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

    [MBProgressHUD hideHUD];

    [MBProgressHUD showWarnMessage:@"网络连接失败..."];
    
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
    [MBProgressHUD showActivityMessageInView:@"加载中..."];
    
    //可以这样 loadURL("firstClick://shareClick?title=分享的标题&content=分享的内容&url=链接地址&imagePath=图片地址");
    
    //ssrj中这样 URL: app-ssrj:collocationId=8152
    
    NSURL *url = [request URL];
    if ([[url scheme] isEqualToString:@"app-ssrj"]) {
        
        NSArray *params = [url.absoluteString componentsSeparatedByString:@":"];
        
        NSString *str = [params lastObject];
        
        NSArray *vauleArr = [str componentsSeparatedByString:@"="];
        
        NSString *IDString = [vauleArr lastObject];
        
        NSString *messageStr = [NSString stringWithFormat:@"这是OC原生的弹窗,id=%@",IDString];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"方式一" message:messageStr delegate:self cancelButtonTitle:@"收到" otherButtonTitles:nil];
        [alert show];
        
        return NO;
    }
    
    return YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    
    [MBProgressHUD hideHUD];
}


#pragma mark -UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == 0) {
        
        [MBProgressHUD hideHUD];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
